/* File: matched_analysis_paper_graphs.do
 * Author: Luca Maini
 * Purpose: this file plots some raw data graphs
 * Output: Figures 3-7, various Online Appendix figures
 *
 */


graph set window fontface "${paperFont}"

use "${coeffdir}\coefficients_sales_final.dta", replace
drop if valeant_ind == 1	// excluded from main analysis

* Calculate number of matched units
count if acquired == 1
forvalues i = 1/5 {
	count if acquired == 1 & cem_varlist == `i'
	}
 

////////////////////////////////////////////////
////										////
////	SECTION 4. Horizontal acquisitions	////
////										////
////////////////////////////////////////////////

* Effect of horizontal acquisitions on net price
twoway 	(kdensity b_w_log_net_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if overlap == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.4)1.2, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(order(2 "Horizontal" "acquisitions" 1 "Placebo") cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure 3b.pdf", as(pdf) replace
graph export "${paperdir}\Figures\Figure 3b.eps", as(eps) replace

* distribution values to be reported in the text
sum b_w_log_net_b if overlap == 1, d
disp exp(r(mean))
sum b_w_log_net_b if placebo == 1, d

* Split effect (HSR) of horizontal acquisitions on net price
twoway 	(kdensity b_w_log_net_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if overlap_nonstealth == 1, ///
			lwidth(*2) lpattern(dash) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if overlap_stealth == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.4)1.2, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(order(2 "Horizontal acquisitions" "above HSR threshold" ///
				 3 "Horizontal acquisitions" "below HSR threshold" ///
				 1 "Placebo") cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure 4b.pdf", as(pdf) replace
graph export "${paperdir}\Figures\Figure 4b.eps", as(eps) replace

sum b_w_log_net_b if overlap_nonstealth == 1, d
sum b_w_log_net_b if overlap_stealth == 1, d
sum b_w_log_net_b if placebo == 1, d


////////////////////////////////////////////
////									////
////	SECTION 5. Portfolio analysis 	////
////									////
////////////////////////////////////////////

* Effect of cross-market acquisitions by larger company on net price
twoway 	(kdensity b_w_log_net_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if lg_acq == 1 & overlap == 0, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.4)1.2, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(order(2 "Cross-mkt. acquisitions" "by larger companies" 1 "Placebo") cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure 6b.pdf", as(pdf) replace
graph export "${paperdir}\Figures\Figure 6b.eps", as(eps) replace


////////////////////////////////////////////
////									////
////	APPENDIX B. Data construction	////
////									////
////////////////////////////////////////////

graph set window fontface "${OAFont}"

use "${coeffdir}\coefficients_sales_final.dta", replace
drop if valeant_ind == 1

* comparison of winsorized and unwinsorized net price placebo distributions
twoway 	(kdensity b_log_net_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if placebo == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.4)1.2, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(order(2 "Winsorized placebo" 1 "Unwinsorized placebo") cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure OA1.pdf", as(pdf) replace

* scatterplot of winsorized vs. unwinsorized coefficients
twoway 	(scatter b_log_net_b b_w_log_net_b if overlap == 1, ///
			msymbol(o) mcolor(gs0)) ///
		(function y = x, range(-2 3)) ///
		, ///
	ylabel(-4(2)4, glcolor(gs14)) ///
	ytitle("{bf:Effect on unwinsorized log net price}") ///
	xlabel(-2(1)3) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(off)
graph export "${paperdir}\Figures\Figure OA2.pdf", as(pdf) replace

* Correlation between list price to net price effects
reg b_w_log_net_b b_log_WAC_b if acquired == 1
twoway 	(lfitci b_w_log_net_b b_log_WAC_b if acquired == 1) ///
		(scatter b_w_log_net_b b_log_WAC_b if acquired == 1, ///
			msymbol(oh) msize(medlarge)), ///
	xtitle("Effect of an acquisition on log list price", height(5)) ///
	ytitle("Effect of an acquisition on log net price") ///
	xlabel(-1(1)2) ylabel(-2(1)3) ///
	legend(off)
graph export "${paperdir}\Figures\Figure OA3.pdf", as(pdf) replace


////////////////////////////////////////////
////									////
////	APPENDIX D. Robustness checks	////
////									////
////////////////////////////////////////////

* Split effect (HSR) of horizontal acquisitions on net price (ATC4)
use "${coeffdir}\coefficients_sales_final.dta", replace
drop if valeant_ind == 1

tab overlap_atc4_nonstealth overlap_atc4_stealth

twoway 	(kdensity b_w_log_net_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if overlap_atc4_nonstealth == 1, ///
			lwidth(*2) lpattern(dash) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if overlap_atc4_stealth == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.4)1.2, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(order(2 "Horizontal acquisitions" "above HSR threshold" ///
				 3 "Horizontal acquisitions" "below HSR threshold" ///
				 1 "Placebo") cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure OA4b.pdf", as(pdf) replace


* Scatterplot of regular vs trend coefficients
twoway 	(lfitci b_w_log_net_b_trend b_w_log_net_b if overlap == 1) ///
		(scatter b_w_log_net_b_trend b_w_log_net_b if overlap == 1, ///
			msymbol(o) mcolor(gs0)), ///
	ylabel(-2(2)4, glcolor(gs14)) ///
	ytitle("{bf:Effect on log net price with differential trends}") ///
	xlabel(-2(1)3) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(off)
graph export "${paperdir}\Figures\Figure OA5.pdf", as(pdf) replace

* Now do a broader correlation check
use "${coeffdir}\coefficients_sales_all.dta", clear
keep if acqd == 1 & valeant_ind == 0
keep b_w_log_net_b Product year cem_varlist cohort_size
replace b_w_log_net_b = . if b_w_log_net_b == 0	// these are missing point estimates bc the sample size is 1

reshape wide b_w_log_net_b cohort_size, i(Product year) j(cem_varlist)

* Scatterplots
twoway	(scatter b_w_log_net_b2 b_w_log_net_b1 if b_w_log_net_b2 != ., ///
			msymbol(Oh) mlcolor(gs0)) ///
		(lfitci b_w_log_net_b2 b_w_log_net_b1 [aweight = cohort_size2] if b_w_log_net_b2 != ., ///
			lcolor(gs0) acolor(gs8%30) alwidth(none) lpattern(solid) lwidth(thick)), ///
	xtitle("Match on Age", height(5)) xlabel(-2(1)3) ///
	ytitle("Match on Age, ATC-1") ylabel(-2(1)3) ///
	legend(off) 
graph export "${paperdir}\Figures\Figure OA6a.png", height(1600) width(1600) as(png) replace

twoway	(scatter b_w_log_net_b3 b_w_log_net_b1 if b_w_log_net_b3 != ., ///
			msymbol(Oh) mlcolor(gs0)) ///
		(lfitci b_w_log_net_b3 b_w_log_net_b1 [aweight = cohort_size3] if b_w_log_net_b3 != ., ///
			lcolor(gs0) acolor(gs8%30) alwidth(none) lpattern(solid) lwidth(thick)), ///
	xtitle("Match on Age", height(5)) xlabel(-2(1)3) ///
	ytitle("Match on Age, ATC-1, Firm Size") ylabel(-2(1)3) ///
	legend(off)
graph export "${paperdir}\Figures\Figure OA6b.png", height(1600) width(1600) as(png) replace

twoway	(scatter b_w_log_net_b4 b_w_log_net_b1 if b_w_log_net_b4 != ., ///
			msymbol(Oh) mlcolor(gs0)) ///
		(lfitci b_w_log_net_b4 b_w_log_net_b1 [aweight = cohort_size4]  if b_w_log_net_b4 != ., ///
			lcolor(gs0) acolor(gs8%30) alwidth(none) lpattern(solid) lwidth(thick)), ///
	xtitle("Match on Age", height(5)) xlabel(-2(1)3) ///
	ytitle("Match on Age, ATC-1, Net Sales") ylabel(-2(1)3) ///
	legend(off)
graph export "${paperdir}\Figures\Figure OA6c.png", height(1600) width(1600) as(png) replace

twoway	(scatter b_w_log_net_b5 b_w_log_net_b1 if b_w_log_net_b5 != ., ///
			msymbol(Oh) mlcolor(gs0)) ///
		(lfitci b_w_log_net_b5 b_w_log_net_b1 [aweight = cohort_size5] if b_w_log_net_b5 != ., ///
			lcolor(gs0) acolor(gs8%30) alwidth(none) lpattern(solid) lwidth(thick)), ///
	xtitle("Match on Age", height(5)) xlabel(-2.5(1)3) ///
	ytitle("Match on Age, ATC-1, Net Sales, Firm Size") ylabel(-2(1)3) ///
	legend(off)
graph export "${paperdir}\Figures\Figure OA6d.png", height(1600) width(1600) as(png) replace


////////////////////////////////////////////
////									////
////	APPENDIX E. Additional results 	////
////									////
////////////////////////////////////////////
use "${coeffdir}\coefficients_sales_final.dta", replace
drop if valeant_ind == 1

////////	E.1	Impact of horizontal acquisitions on other outcomes

* horizontal acquisitions and list price
twoway 	(kdensity b_log_WAC_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_log_WAC_b if overlap_nonstealth == 1, ///
			lwidth(*2) lpattern(dash) lcolor(gs0)) ///
		(kdensity b_log_WAC_b if overlap_stealth == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.5)2, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log list price}", height(6)) ///
	legend(order(2 "Horizontal acquisitions" "above HSR threshold" ///
				 3 "Horizontal acquisitions" "below HSR threshold" ///
				 1 "Placebo") cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure OA13b.pdf", as(pdf) replace

* cross-market acquisitions and list price
twoway 	(kdensity b_log_WAC_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_log_WAC_b if cross_market == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.5)2, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log list price}", height(6)) ///
	legend(order(2 "Cross-mkt. acquisitions" "by larger companies" 1 "Placebo") cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure OA14b.pdf", as(pdf) replace



////////	E.2	Spillover effects of stealth horizontal acquisitions

* Same ATC-3 drugs
use "${coeffdir}\coefficients_sales_final.dta", replace
drop if valeant_ind == 1

twoway 	(kdensity b_w_log_net_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if stlth_same_atc3_spill == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.5)1.5, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(order(2 "Drugs in the same" ///
				   "ATC-3 of a stealth" ///
				   "horizontal acquisition" ///
				 1 "Placebo") size(*0.95) cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure OA18b.pdf", as(pdf) replace

* Spillover effect of small horizontal acquisitions (same ATC-4 drugs)
twoway 	(kdensity b_w_log_net_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if stlth_same_atc3_comp == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.5)1.5, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(order(2 "Drugs in the same ATC-4" ///
				   "as drugs involved in a" ///
				   "stealth horizontal acq." ///
				 1 "Placebo") size(*0.95) cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure OA18d.pdf", as(pdf) replace


////////	E.4	Acquisitions by smaller companies

* Effect of cross-market acquisitions by smaller company on net price
twoway 	(kdensity b_w_log_net_b if placebo == 1, ///
			lwidth(*2.5) lpattern(dot) lcolor(gs0)) ///
		(kdensity b_w_log_net_b if placebo == 0 & overlap == 0 & sm_acq == 1, ///
			lwidth(*2) lpattern(solid) lcolor(gs0)) ///
		, ///
	ylabel(0(0.4)1.2, nogrid format(%4.1f)) ytitle("{bf:Density}") ///
	xlabel(#8) xtitle("{bf:Effect on log net price}", height(6)) ///
	legend(order(2 "Cross-mkt. acquisitions" "by smaller companies" 1 "Placebo") cols(1) ///
		   ring(0) bplacement(11) region(color(none)))
graph export "${paperdir}\Figures\Figure OA19b.pdf", as(pdf) replace



*** END CODE
